using FluentNHibernate.Mapping;
using Wikey.Entity;

namespace Wikey.Domain.Mappings
{
    public class PageMap : ClassMap<Page> {
        public PageMap() {
            Id(x => x.Id);
            Map(x => x.Name).Not.Nullable().Length(100);
            Map(x => x.FriendlyName).Length(200);
            Map(x => x.Published).Not.Nullable();
            Map(x => x.ViewCount).Nullable();
            Map(x => x.Description).Nullable().Length(200);
            Map(x => x.CreatedAt).Nullable();
            Map(x => x.ModifiedAt).Nullable();
            Map(x => x.Tags).Nullable().Length(1000);
            References(x => x.Space).Column("SpaceId").Cascade.All();
            References(x => x.Parent).Column("ParentId").Cascade.All();
            References(x => x.CreatedBy).Column("CreatedBy").Cascade.All();
            References(x => x.ModifiedBy).Column("ModifiedBy").Cascade.All();
            HasMany(x => x.Comments).Inverse().KeyColumn("PageId").Cascade.All();
            HasMany(x => x.Documents).Inverse().KeyColumn("PageId").Cascade.All();
            HasMany(x => x.SubPages).Inverse().KeyColumn("ParentId").Cascade.All();
            HasMany(x => x.PageContentNodes).Inverse().KeyColumn("PageId").Cascade.All();

            Not.LazyLoad();
        }
    }
}